package org.gwt.pluginframework.exceptionhandler.client;

import org.gwt.pluginframework.common.Plugin;
import org.gwt.pluginframework.common.exception.PluginException;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ExceptionTriggerPlugin extends Plugin {

	private static final long serialVersionUID = 2579449940078203297L;
	
	private static final String INJECTION_POINT = "exeptionTriggerPoint";
	
	public void setupManifest() {
		manifest.setName("ExceptionTriggerPlugin");
		manifest.setVersion("1.0");
		manifest.setComment("My new Exception Trigger Plugin plugin!");
	}
	
	@Override
	public void onStart() {
		Panel panel = new VerticalPanel();
		panel.add(new Label("Try out new magic button!"));
		panel.add(new Button("Hit me!", new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				getPluginManager().handle(
						new PluginException(ExceptionTriggerPlugin.this, 
								new RuntimeException("This button does not work well ;)")));
			}
		}));
		
		// injecting plug-ins panel with help of native GWT function
		RootPanel.get(INJECTION_POINT).add(panel);
	}
}
